#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main()
{
    pid_t id = fork();
    int val = 0;
    if(id == 0)
    {
        //子进程
        printf("child change before pid:%d,ppid:%d,val=%d,&val=%p\n",getpid(),getppid(),val,&val);
        sleep(1);
        val = 100;
        printf("child change after pid:%d,ppid:%d,val=%d,&val=%p\n",getpid(),getppid(),val,&val);
    }
    else if(id < 0)exit(0);
    else 
    {
        //父进程
        printf("father process pid:%d,ppid:%d,val=%d,&val=%p\n",getpid(),getppid(),val,&val);
        sleep(5);
        printf("father process pid:%d,ppid:%d,val=%d,&val=%p\n",getpid(),getppid(),val,&val);
    }
    return 0;
}



//int g_val = 100;//已初始化数据段
//int g_unval; //未初始化数据段
//
//int main()
//{
//
//    char* heap1 = (char*)malloc(1);
//    char* heap2 = (char*)malloc(1);
//    char* heap3 = (char*)malloc(1);
//    char* heap4 = (char*)malloc(1);
//    char* heap5 = (char*)malloc(1);
//    //先验证堆
//    printf("heap1 addr:%p\n",heap1);
//    printf("heap2 addr:%p\n",heap2);
//    printf("heap3 addr:%p\n",heap3);
//    printf("heap4 addr:%p\n",heap4);
//    printf("heap5 addr:%p\n",heap5);
//    printf("\n\n");
//    //再验证栈
//    printf("stack1 addr:%p\n",&heap1);
//    printf("stack2 addr:%p\n",&heap2);
//    printf("stack3 addr:%p\n",&heap3);
//    printf("stack4 addr:%p\n",&heap4);
//    printf("stack5 addr:%p\n",&heap5);

  //  printf("code addr:%p\n",&main);//main实际上就是正文代码，在代码段
  //  printf("init data addr:%p\n",&g_val);//已初始化数据段
  //  printf("uninit data addr:%p\n",&g_unval);//未初始化数据段

  //  char* heap = (char*)malloc(1);

  //  printf("heap addr:%p\n",heap);//heap中的值就是堆的空间
  //  printf("stack addr:%p\n",&heap);//heap是一个临时变量，这个变量是保存在栈上的
  //  printf("command addr:%p\n",argv);//命令行参数
  //  printf("environ addr:%p\n",env);//环境变量
//    return 0;
    

//}
